package cn.itcast.n4_共享模型_管程;

import lombok.extern.slf4j.Slf4j;
import org.openjdk.jol.info.ClassLayout;

/**
 * @program: juc
 * @description: -XX:-UseBiasedLocking
 * @author: flyduck
 * @create: 2024-09-25 16:09
 **/
@Slf4j(topic = "c.Test16_偏向锁撤销方式1_调用hashcode方法会撤销偏向锁")
public class Test16_偏向锁撤销方式1_调用hashcode方法会撤销偏向锁 {
    public static void main(String[] args) throws InterruptedException {
        Thread.sleep(4000);

        Dog dog = new Dog();
        dog.hashCode();
        log.debug("加锁前对象的mark word:{}",ClassLayout.parseInstance(dog).toPrintableSimple());//00000000 00000000 00000000 01101100 01100010 10011101 01101110 00000001

        synchronized (dog) {
            log.debug("加锁后对象的mark word:{}",ClassLayout.parseInstance(dog).toPrintableSimple());//00000000 00000000 00000000 00000000 00000010 11000111 11110110 11111000
        }

        log.debug("解锁后对象的mark word:{}",ClassLayout.parseInstance(dog).toPrintableSimple());//00000000 00000000 00000000 01101100 01100010 10011101 01101110 00000001
    }
}


